﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Panel.Master" Inherits="System.Web.Mvc.ViewPage<Prodma.DataAccess.Models.ViewModels.RoleVm>" %>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
	<%=System.Configuration.ConfigurationManager.AppSettings["pageTitle"] %>
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">

<div class="listHeader">
    <img src="../../Images/ListImages/rolelist.png" alt="" class="listHeaderIco" />
    <div class="listHeaderText">Yetki Yöneticisi : <%=ViewData.Model.Name %></div>
    
    <div class="listHeaderMenuBox">
        <% Html.RenderPartial("/views/shared/userControls/acceptance.ascx",
               new Prodma.DataAccess.Models.UserControlViewModels.AcceptanceVm() { View = "role" }); %>
    </div>
</div>

<form method="post" action="/role/edit/">
<div class="detailContainer">
    <div class="detailSection-50pc">
        <div class="detailSectionHeader">Giriş Bilgileri</div>
        <div class="detailSectionRow">
            <div class="detailSectionRowTitle-20pc">Adı :</div>
            <div class="detailSectionRowText-80pc"><input type="text" id="name" name="name" maxlength="50" class="detailSectionControl" value='<%=ViewData.Model.Name %>' /></div>
        </div>
    </div>
    <div class="detailSection-50pc">
        <div class="detailSectionHeader">Sistem Bilgileri</div>
        <div class="detailSectionRow">
            <div class="detailSectionRowTitle-20pc">Durum :</div>
            <div class="detailSectionRowText-80pc"><%=Html.DropDownList("ddlState", (SelectList)ViewData["stateList"], "Seçiniz", new { @class = "detailSectionControlCombo" })%></div>
        </div>
    </div>
    <div class="detailSection-50pc">
        <div class="detailSectionHeader">Yetkilendirme</div>
        <div class="detailSectionRow">
            <div class="detailSectionRowTitle-20pc">Bölge :</div>
            <div class="detailSectionRowText-80pc"><%=Html.DropDownList("ddlMenuAdminParent", (SelectList)ViewData["menuAdminParentList"], "Seçiniz", new { @class = "detailSectionControlCombo" })%></div>
        </div>
        <div class="detailSectionRow">
            <div class="detailSectionRowTitle-20pc">Menü :</div>
            <div class="detailSectionRowText-80pc">
                <select id="ddlMenuAdminSub" class="detailSectionControlCombo">
                    <option value="0">Seçiniz</option>
                </select>
            </div>
        </div>
        <div class="detailSectionRow">
            <div class="detailSectionRowTitle-20pc">Okuma :</div>
            <div class="detailSectionRowText-80pc"><input type="checkbox" id="chkRead" class="detailSectionControlChk" /></div>
        </div>
        <div class="detailSectionRow">
            <div class="detailSectionRowTitle-20pc">Yazma :</div>
            <div class="detailSectionRowText-80pc"><input type="checkbox" id="chkWrite" class="detailSectionControlChk" /></div>
        </div>
        <div class="detailSectionRow">
            <div class="detailSectionRowTitle-20pc">Düzetme :</div>
            <div class="detailSectionRowText-80pc"><input type="checkbox" id="chkUpdate" class="detailSectionControlChk" /></div>
        </div>
        <div class="detailSectionRow">
            <div class="detailSectionRowTitle-20pc">Silme :</div>
            <div class="detailSectionRowText-80pc"><input type="checkbox" id="chkDelete" class="detailSectionControlChk" /></div>
        </div>
        <div class="detailSectionRow">
            <div class="detailSectionRowTitle-20pc"></div>
            <div class="detailSectionRowText-80pc"><input type="button" id="acceptAuthorization" value="Onayla" class="detailSectionControl" /></div>
        </div>
    </div>
    <input type="hidden" id="id" name="id" value='<%=ViewData.Model.Id %>' />
</div>
</form>

<script type="text/javascript">
    function submitForm() {
        if (roleValidate()) {
            document.forms[0].submit();
        }
    }
    $(function() {
        $('#ddlMenuAdminParent').change(function() {
            $.getJSON('/role/getMenuAdminSubItems/?parentId=' + $('#ddlMenuAdminParent :selected').val(), null, function(data) {
                $("#ddlMenuAdminSub").fillSelect(data);

                $.getJSON('/role/getAuthorization/?roleId=' + $('#id').val() + '&menuId=' + $('#ddlMenuAdminParent :selected').val(), null, function(data) {
                    if (data != 0) {
                        $('#chkRead').attr('checked', data.Read);
                        $('#chkWrite').attr('checked', data.Write);
                        $('#chkUpdate').attr('checked', data.Update);
                        $('#chkDelete').attr('checked', data.Delete);
                    }
                    else {
                        $('#chkRead').attr('checked', 0);
                        $('#chkWrite').attr('checked', 0);
                        $('#chkUpdate').attr('checked', 0);
                        $('#chkDelete').attr('checked', 0);
                    }
                });

                $('#ddlMenuAdminSub').append($('<option></option>').val(0).html('Seçiniz'));
                document.getElementById('ddlMenuAdminSub').selectedIndex = document.getElementById('ddlMenuAdminSub').length - 1;
            });
        });
    });
    $(function() {
        $('#ddlMenuAdminSub').change(function() {
            $.getJSON('/role/getAuthorization/?roleId=' + $('#id').val() + '&menuId=' + $('#ddlMenuAdminSub :selected').val(), null, function(data) {
                if (data != 0) {
                    $('#chkRead').attr('checked', data.Read);
                    $('#chkWrite').attr('checked', data.Write);
                    $('#chkUpdate').attr('checked', data.Update);
                    $('#chkDelete').attr('checked', data.Delete);
                }
                else {
                    $('#chkRead').attr('checked', 0);
                    $('#chkWrite').attr('checked', 0);
                    $('#chkUpdate').attr('checked', 0);
                    $('#chkDelete').attr('checked', 0);
                }
            });
        });
    });

    $(function() {
        $('#acceptAuthorization').click(function() {
            var roleId = $('#id').val();
            var menuId = 0;
            if ($('#ddlMenuAdminSub :selected').val() == 0) {
                menuId = $('#ddlMenuAdminParent :selected').val();
            }
            else {
                menuId = $('#ddlMenuAdminSub :selected').val();
            }
            var read = $('#chkRead').attr('checked');
            var write = $('#chkWrite').attr('checked');
            var update = $('#chkUpdate').attr('checked');
            var deleted = $('#chkDelete').attr('checked');

            $.getJSON('/role/updateAuthorization/?roleId=' + roleId + '&menuId=' + menuId + '&read=' + read + '&write=' + write + '&update=' + update + '&delete=' + deleted, null, function(data) {
                alert('İşlem onaylandı.');
            });
        });
    });
</script>

</asp:Content>
